| Conditions | 1 |
| Paths | 1 |
| Total Lines | 67 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 1 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | var chai = require('chai') |
||
| 70 | describe('Test SMS API', function () { |
||
| 71 | xit('it should send an sms', function (done) { |
||
| 72 | nock('https://www.my-cool-sms.com') |
||
| 73 | .get('/api-socket.php') |
||
| 74 | .reply(200, { |
||
| 75 | 'success': true, |
||
| 76 | 'smsid': 'ce184cc0a6d1714d1ac763f4fe89f521', |
||
| 77 | 'body': 'Have a nice day!', |
||
| 78 | 'bodyucs2': '0048006100760065002000610020006E00690063006500200064', |
||
| 79 | 'bodygsm7': '486176652061206E6963652064617921', |
||
| 80 | 'number': '+491234567890', |
||
| 81 | 'senderid': '+449876543210', |
||
| 82 | 'senderidenabled': true, |
||
| 83 | 'unicode': false, |
||
| 84 | 'numchars': 321, |
||
| 85 | 'escapenumchars': 0, |
||
| 86 | 'smscount': 3, |
||
| 87 | 'charge': 0.112, |
||
| 88 | 'balance': 752.121, |
||
| 89 | 'countrycode': 'IE', |
||
| 90 | 'prefix': '+353', |
||
| 91 | 'timestamp': '2017-04-02T22:27:22-07:00', |
||
| 92 | 'callbackurl': 'https://www.groganburners.ie/api/sms/callback' |
||
| 93 | }) |
||
| 94 | |||
| 95 | var mail = { |
||
| 96 | number: '+353873791474', |
||
| 97 | message: 'Hello' |
||
| 98 | } |
||
| 99 | chai.request(server) |
||
| 100 | .post(prefix + '/sms') |
||
| 101 | .send(mail) |
||
| 102 | .end(function (err, res) { |
||
| 103 | should.not.exist(err) |
||
| 104 | res.should.have.status(200) |
||
| 105 | res.body.should.be.a('object') |
||
| 106 | res.body.should.have.property('message').eql('Message sent') |
||
| 107 | nock.cleanAll() |
||
| 108 | done() |
||
| 109 | }) |
||
| 110 | }) |
||
| 111 | |||
| 112 | it('it should fail to send an sms to invalid number', function (done) { |
||
| 113 | nock('https://www.my-cool-sms.com') |
||
| 114 | .get('/api-socket.php') |
||
| 115 | .reply(200, { |
||
| 116 | success: false, |
||
| 117 | errorcode: '210', |
||
| 118 | description: 'The number seems to be invalid' |
||
| 119 | }) |
||
| 120 | var mail = { |
||
| 121 | number: '+35386', |
||
| 122 | message: 'Hello' |
||
| 123 | } |
||
| 124 | chai.request(server) |
||
| 125 | .post(prefix + '/sms') |
||
| 126 | .send(mail) |
||
| 127 | .end(function (err, res) { |
||
| 128 | should.exist(err) |
||
| 129 | res.should.have.status(404) |
||
| 130 | res.body.should.be.a('object') |
||
| 131 | err.should.have.property('message').eql('Not Found') |
||
| 132 | nock.cleanAll() |
||
| 133 | done() |
||
| 134 | }) |
||
| 135 | }) |
||
| 136 | }) |
||
| 137 |
This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.